import { check } from 'meteor/check';
import { Channels } from '/imports/models/Channels';

/**
 * 获取用户创建的频道列表
 * @param {Object} query
 * @param {Number} limit
 */
Meteor.publish('get.user.channels', function (query, limit) {
  check(query.userId, String);
  check(limit, Number);

  const selector = {
    'owner.id': query.userId
  };

  Counts.publish(this, 'get.user.channels.counts', Channels.find(selector));

  return Channels.find(selector, {
    limit: limit,
    sort: {
      createdAt: -1
    }
  });
});